package com.yonyou.pmclouds.messagenotice.constructor.impl;

import com.yonyou.pmclouds.basecom.consts.BillTypeConst;
import com.yonyou.pmclouds.basecom.entity.Entity;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.messagenotice.entity.MessageNoticeVO;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.project.rmiitf.ProjectSimpleQuery;
import com.yonyou.pmclouds.workstartreport.entity.WorkStartVO;
import com.yonyou.pmclouds.workstartreport.rmiitf.WorkStartQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class WorkStartMessageConstructor extends AbstractMessageNoticeConstructor {

    private final WorkStartQuery query;

    private final ProjectSimpleQuery projectSimpleQuery;

    @Autowired
    public WorkStartMessageConstructor(WorkStartQuery query, ProjectSimpleQuery projectSimpleQuery) {
        this.query = query;
        this.projectSimpleQuery = projectSimpleQuery;
    }


    @Override
    protected MessageNoticeVO[] generateContent(Entity vo) throws BusinessException {
        MessageNoticeVO noticeVO = coverBusinessVOToMessageVO(vo);
        if(noticeVO == null){
            return null;
        }
        // 您提交的【变更申请/签证申请】已审批通过
        // 您提交的【变更申请/签证申请】已被驳回
        WorkStartVO report = query.getReport(noticeVO.getRelateKey());
        //AlterVO alterVO = query.getById(noticeVO.getRelateKey());
        ProjectVO projectVO = projectSimpleQuery.queryProject(report.getPkProject());

        String prefix = getApprovalPrefixMessage(report.getBillstatus());
        String messageContent = APPROVAL_PREFIX_MESSAGE + "[" +
                projectVO.getSname()
                 + "]的开工报告，" + prefix;

        noticeVO.setMessageTitle(projectVO.getSname());
        noticeVO.setMessageReceiver(report.getCreator());
        noticeVO.setPkTenant(report.getPkTenant());
        noticeVO.setMessageContent(messageContent);
        noticeVO.setRelateType(report.getBillType());

        return new MessageNoticeVO[]{noticeVO};
    }

    @Override
    public String getRelateType() {
        return BillTypeConst.WORKSTART_BILLTYPE;
    }
}
